home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq21.zip / JOINCONF.SLT < prev    next >
Text File  |  1992-03-20  |  11KB  |  325 lines

  1. //-----------------------------------------------------------
  2. // JOINCONF.SLT Join Conference.
  3.  
  4. // If you have suggestions for improving this script, please suggest
  5. // improvements to me via old-fashioned snail-mail to:
  6.  
  7. // Author:  Inge Vabekk
  8. //          Hamangskogen 108
  9. //          N-1300 SANDVIKA
  10. //          NORWAY
  11. //          tel. (472) 546 396
  12.  
  13. str bbs_type  [32]           // BBS type.
  14.    ,PrevConf  [20]=""        // Previous conference.
  15.    ,NextConf  [20]=""        // Next conference.
  16.    ,command   [10]           // Command prompt.
  17.    ,temp      [4]            // Temporary for short strings.
  18.                              // For the Global storage:
  19.    ,global   []="GLOBAL"     // Global script.
  20.    ,bbstype  []="BTYPE"      // BBS type.
  21.    ,conf     []="CONF"       // Current conference
  22.    ,prompt   []="PROMPT"     // Current command prompt.
  23.    ,ronly    []="RONLY"      // Read Only conference.
  24.    ;     
  25.  
  26. int tol = 100                          // No activity for 10 sec.
  27.    ,stat, tmark                        // makes script time out. 
  28.    ,mbbs, pcb, rbbs, opus, fido, crcs 
  29.    ,Enter=13
  30.    ;
  31.  
  32. //-----------------------------------------------------------   
  33. // Script starts here.
  34. //-----------------------------------------------------------   
  35.  
  36. main (str NewConf)
  37. {
  38. int c, i, j, ercnt, switched
  39.    ,yes, ent, par, con, com, bad, ro, co, y;
  40. str Sline [80]
  41.    ,pre    [4]
  42.    ,post   [4]
  43.    ,end    [4]
  44.    ,ans   [14]
  45.    ;
  46.  
  47.    NextConf = NewConf;                 // Use local, since it may
  48.                                        // be changed.
  49. // Only if online.
  50.  
  51.   if (!carrier())  
  52.   { failtone();
  53.     status_wind ("T²: YOU CAN'T JOIN A CONFERENCE IF YOU'RE OFFLINE!",20);
  54.     return (-1);
  55.   }
  56.  
  57.   read (bbstype,bbs_type);             // Get BBS type. 
  58.   read (conf,PrevConf);                // Get previous conference.
  59.   read (prompt,command);               // Get command prompt.
  60.  
  61.   mbbs = pcb = rbbs = opus = fido = crcs = 0;
  62.   if      (bbs_type == "MBBS") mbbs = 1;
  63.   else if (bbs_type == "PCB")   pcb = 1;
  64.   else if (bbs_type == "RBBS") rbbs = 1;
  65.   else if (bbs_type == "OPUS") opus = 1;
  66.   else if (bbs_type == "FIDO") fido = 1;
  67.   else if (bbs_type == "CRCS") crcs = 1;
  68.   else                                          
  69.   { wrongBBS(bbs_type);                  // Don't know how to do it!
  70.     return (-1);
  71.   }
  72.  
  73.   if (mbbs)
  74.   { pre  = "(";                          // Define the delimiters
  75.     post = ")";                          // for the conference
  76.     end = "Q^M";                         // name.
  77.   }
  78.   else if (pcb)
  79.   { pre  = "t) ";
  80.     post = " (";
  81.     end = "^M";
  82.   }
  83.   else if (rbbs)
  84.   { pre  = "";
  85.     post = " Co";   
  86.     end = "^M";
  87.   }
  88.   co = strlen(pre);                      // Length of prefix.
  89.  
  90.   flush();
  91.   y=gety();
  92.   if (rbbs)
  93.   { --y;                                 // RBBS:
  94.     if (y<0) y=0;                        // Conf. name on previous line.
  95.   }
  96.   vgetchrs(0,y,Sline,0,80);              // Get command line from screen.
  97.  
  98.   if (pcb)                               // PCBoard: Do some extra checks
  99.   { if (strposi(PrevConf,"Main",0)== 0   // for Main Board.
  100.      || strposi(Sline,"Main Boa",0) > 0)
  101.     { PrevConf = "Main Board";           // Set Main Board.
  102.       write (conf,PrevConf);
  103.     }
  104.   }
  105.  
  106.   if (strlen(PrevConf) < 1) do         // Have to find which conference
  107.   { j = -1;
  108.     vgetchrs(0,gety(),Sline,0,80);     // Get command line from screen.
  109.     if (rbbs)                          // RBBS: Conference name
  110.       i = 0;                           // at beginning of line.
  111.     else
  112.     { i = strposi(Sline,pre,0);        // Find start byte.
  113.       if (i < 0)
  114.       { i = strposi(Sline,"[",0);      // Not found: Try "[".
  115.         if (i >= 0)                    // Is this the old format?
  116.         { co = 1;                      // Yepp.
  117.           pre  = "[";                  // Starts with a left bracket,
  118.           post = "]";                  // ends with a right bracket.
  119.         }
  120.       }
  121.       i = i+co;                        // Proceed to conference name.
  122.     }
  123.     j = strposi (Sline,post,i);        // Find end byte.
  124.  
  125.     j = j-i;                           // Find the length.
  126.     if (j>0) 
  127.       substr (Sline,i,j,PrevConf);     // Conference found!
  128.     else
  129.       cputs (end);                     // Not found: Back to Main.
  130.     flush();
  131.   } while (j < 1);
  132.  
  133. // Previous conference known.
  134.  
  135.   for (i=0; subchr(NextConf,i)<=' ';++i) // Find first non-space.
  136.     ;                                  // Find end of line.
  137.   j = -1;
  138.   for (; (c=subchr(NextConf,i)) > ' ' ;++i)
  139.     setchr(NextConf,++j,c);            // Get up to first space.
  140.   setchr(NextConf,++j,0);
  141.  
  142.   ercnt = switched = 0;
  143.   if (pcb)
  144.   { if (strposi(NextConf,"Main",0) >= 0)
  145.       NextConf = "Main Board";           // Only one legal name
  146.     if (strposi(PrevConf,"Main",0) >= 0) // for Main Board.
  147.       PrevConf = "Main Board";
  148.   }
  149.  
  150.   if (strposi(PrevConf,NextConf,0)==0) // Same conference?
  151.   { if (!mbbs) return (0);             // Ignore unless it's MBBS.
  152.     if (strposi (Sline," Read ",0) >= 0) return 0;  // Read; OK.
  153.     cputs ("^M");                      // No, get Read Command
  154.     waitfor (command,1);               // and wait.
  155.     return 0;
  156.   }
  157.   
  158.   while (!switched && ercnt < 4)       // Until conference changed:
  159.   { if (pcb && strposi(NextConf,"Main Board",0)==0)
  160.       cputs("A");                      // Abandon Main Board.
  161.     else
  162.     { cputs("J ");                     // join the conference.
  163.       cputs(NextConf);
  164.     }
  165.     write (ronly,"NO");                // NOT read only.
  166.     ans = "";                          // Next answer.
  167.     con = track (NextConf,1);          // Check conference name.
  168.     if (pcb)
  169.     { ent = track("(Enter)=",0);
  170.       par = track("left)",0);          // ...minutes left
  171.       com = track(command,0);
  172.       bad = 0;
  173.     }
  174.     else
  175.     { par = -948;                      // Not used for MBBS.
  176.       if (mbbs)
  177.       { com = track(command,0);
  178.         ent = track("nter=none>:",0);  // Wrong selection.
  179.         bad = track("lid command",0);  // Invalid command.
  180.         ro = track("READ ONLY",0);     // Read Only conference.
  181.       }
  182.       else if (rbbs)
  183.       { com = track("V,W,X>?",0);
  184.         ans = "n^M";                   // Browse conference without
  185.         ent = track("Y,[N])?",0);      // permanently joining (Y,[N])?
  186.         switched = 1;
  187.       }
  188.     }
  189.   
  190.     flush();
  191.     cputs("^M");
  192.     tmark = timer_start (tol);         // Just 10 sec. time-out.
  193.  
  194.     while ((stat=trig()) > 0 && ++ercnt < 4) // Wait for Command.
  195.     { if (stat == ent)
  196.       { ++ercnt;
  197.         if (pcb)                       // PCBoard:
  198.         { terminal();
  199.           y=gety();
  200.           vgetchrs(0,y,Sline,0,80);    // Get command line from screen.
  201.           if (strpos (Sline,"Mail Com") >=0)
  202.             ans = "qu";    // .... Main Board (0) Mail Command: (Enter)='xx...
  203.           else
  204.             ans = "n";                 // Scan since last read?
  205.         }                              // Scan for personal mail?
  206.         else if (mbbs)
  207.           ans = NextConf;              // Wrong conference. Try again.
  208.  
  209.         cputs (ans);                   // Send answer.
  210.         cputs ("^M");
  211.       }
  212.       else if (stat == par)            // (Quit from mail command)
  213.         break;                         // ...minutes left)
  214.  
  215.       else if (stat == bad)            // Invalid command:
  216.       { prints ("???? ERROR ????");
  217.         break;                         // Try again.
  218.       }
  219.       else if (stat == com)            // Command:
  220.       { if (switched)                  // Check switch. If non-zero
  221.           write (conf,NextConf);       // we're in this conference.
  222.         break;
  223.       }
  224.       else if (stat == ro)             // Read Only conference?
  225.         write (ronly,"YES");           // Mark it.
  226.  
  227.       else if (stat == con)            // Conference name?
  228.       { --ercnt;
  229.         switched = 1;                  // We've switched.
  230.       }
  231.     }
  232.     track_free(0);